package com.zhuhai.service;

import com.zhuhai.entity.Pnr;
import com.zhuhai.repository.PnrReposity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 *
 *  pnr Service
 *  @author zhuhai
 *  @version 1.0.0.0
 */
@Service
public class PnrService {

    @Resource
    private PnrReposity pnrReposity;

    /**
     * 为pnr、passenger建立@OneToMany 关系，并使用默findAll方法查询出pnr记录，同时查询出pnr中的旅客信息
     * @param pageable
     * @return
     */
    public Page<Pnr> getPnrList(final Pageable pageable) {
        return pnrReposity.findAll(pageable);
    }

    /**
     * 保存pnr
     * @param pnr
     */
    @Transactional(rollbackFor = Exception.class)
    public void save(final Pnr pnr){
        pnrReposity.save(pnr);
    }

    /**
     * 删除pnr
     * @param id
     */
    @Transactional(rollbackFor = Exception.class)
    public void deleteById(final Integer id){
        pnrReposity.deleteById(id);
    }

    /**
     * 獲取pnr
     * @param id
     * @return
     */
    public Pnr getPnr(final Integer id) {
        return pnrReposity.getPnrById(id);
    }
}
